<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{margin:0;padding:0}
        #test{
            position: absolute;
            width:200px;
            height: 100px;
            background: red;
            left:50%;
            top:50%;
            transform: translate(-50%,-50%);
        }
        #test:hover{
            cursor: grab;
        }

    </style>
    <script src="lib/jquery-3.4.1.js"></script>
</head>
<body>
    <div id="test">

    </div>
    <script>
        $("#test").mousedown(function(event){
            var pageX = event.clientX;
            var pageY = event.clientY;
            var offsetX = $(this).offset().left;
            var offsetY = $(this).offset().top;
            var spaceX = pageX - offsetX;
            var spaceY  = pageY - offsetY;
            /* 移动的事件 */
            $(document).bind('mousemove',function(event){
                let clientX = event.clientX;
                let clientY = event.clientY;
                var x = clientX - spaceX;
                var y = clientY - spaceY;
                $("#test").css({left:x+100+"px",top:y+50+"px"})
            })
        })
        $("#test").mouseup(function(){
            $(document).unbind("mousemove")
        })
    </script>
</body>
</html>